package cn.gok;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Author Linyh
 * @Description
 * @Date 2022/7/13 19:57
 **/

public class TestMain {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class<User> userClass = User.class;
        Field[] fields = userClass.getDeclaredFields();
        User user = userClass.newInstance();
        for (Field field : fields) {
            NotNull notNull = field.getAnnotation(NotNull.class);
            if (notNull != null){
                String fieldGetMethod = "getName";
                Method method = userClass.getDeclaredMethod(fieldGetMethod);
                Object invoke = method.invoke(user);
                if (invoke == null){
                    System.out.println(notNull.name()+notNull.value());
                }else {
                    System.out.println(notNull.name()+"不为空");
                }
            }

        }
    }
}
